﻿using System;
using System.Collections.Generic;
using System.Text;

namespace GroupMappedDiskSnapInExtension
{
    public class MarshalBuffer
    {
        byte[] _buffer = null;

        public MarshalBuffer(uint size)
        {
            _buffer = new byte[size];
        }

        public MarshalBuffer(byte[] buffer)
        {
            _buffer = buffer;
        }

        public int ReadInt(uint offset)
        {
            return BitConverter.ToInt32(_buffer, (int) offset);
        }

        public long ReadChar(uint offset)
        {
            return BitConverter.ToChar(_buffer, (int) offset);
        }

        public string ReadString(uint offset)
        {
            StringBuilder str = new StringBuilder();
            uint i = 0;
            while(this.ReadChar(offset + i) != (char) 0)
            {
                str.Append((char) this.ReadChar(offset + i));
                i = i + 2;
            }
            return str.ToString();
        }
    }
}
